﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace 毕业设计__排课软件
{
    /// <summary>
    /// Lesson_Info.xaml 的交互逻辑
    /// </summary>
    public partial class Lesson_Info : Window
    {
        readonly string _dbPath;
        List<Lesson_Info_> teacher_info = new List<Lesson_Info_>();
        public Lesson_Info()
        {
            InitializeComponent();
            var path0 = Environment.CurrentDirectory;
            var path1 = path0.Substring(0, path0.LastIndexOf("\\", StringComparison.Ordinal));
            var path2 = path1.Substring(0, path1.LastIndexOf("\\", StringComparison.Ordinal));
            _dbPath = path2 + "\\DB\\bs_pk.db";
            using (var conn1 = new SQLiteConnection())
            {
                var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                conn1.ConnectionString = connsb.ToString();
                conn1.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                {
                    string sql1 = string.Format("select Course_Name,Course_Type,Theory_Class,Experiment_Class,Total_Class from Lesson_Info");
                    cmd.CommandText = sql1;
                    SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                    DataSet data = new DataSet();
                    adapter.Fill(data);
                    DataTable table = data.Tables[0];
                    foreach (DataRow tr in table.Rows)
                    {
                        Lesson_Info_ temp = new Lesson_Info_();
                        temp.Course_Name = tr["Course_Name"].ToString();
                        temp.Course_Type = tr["Course_Type"].ToString();
                        temp.Theory_Class = tr["Theory_Class"].ToString();
                        temp.Experiment_Class = tr["Experiment_Class"].ToString();
                        temp.Total_Class = tr["Total_Class"].ToString();
                        teacher_info.Add(temp);
                    }
                }
            }
            dg1.ItemsSource = teacher_info;
        }
    }
}
